//
// Created by glyn on 2024/3/15.
//
#pragma once

#include "dgramdomainsocket.hpp"
#include <thread>

template <uint16_t BUFFER_SIZE = AS_DOMAIN_BUFFER_SIZE>
class DgramDomainServer : public DgramDomainSocket<BUFFER_SIZE>
{
public:
    // Enable or disable the SO_BROADCAST flag
    void setBroadcast(bool value, FDR_ON_ERROR)
    {
        int broadcast = static_cast<int>(value);
        int status = setsockopt(this->sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof broadcast);
        if (status == -1)
        {
            onError(errno, "setsockopt(SO_BROADCAST) failed.");
            return;
        }
    }
};